<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
set_html('title','我的订单');
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page');
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']);
    $orderby='level asc';
	$total='';
	$levels=$this->getall('level',$params,array(),'',$orderby);
	foreach($levels as &$item){
		$params=array('mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid']);
		if(isset($_RQ['type'])){
			$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		}
		$item['num']=pdo_count('jy_merch_creditlog',$params);
	}
	$return['levels']=$levels;
	$return['params']=array(
		'level'=>$levels['id'],
		'page'=>1,
	);
	$params=array('plugin'=>'jy_merchjifee','uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid']);
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		$return['params']['type']=$_RQ['type'];
	}
	$return['commission_money']=pdo_getsum('jy_merch_creditlog',$params,'fee');
	$return['commission_total']=pdo_count('jy_merch_creditlog',$params);
	$return['list']=array();
	$return['psize']=20;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('plugin'=>'jy_merchjifee','mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid']);
	if(isset($_RQ['type'])){
		$params['type']=$_RQ['type']!=0?$_RQ['type']:array(0,3);
		$return['params']['type']=$_RQ['type'];
		//$params['type']=$_RQ['type'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=pdo_getlist('jy_merch_creditlog',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'ordersn'=>$item['ordersn']));
		$item['member']=model('core/member')->basic($order['mid']);
		$item['goodsid']=pdo_getcolumn('jy_weishop_order_goods',array('orderid'=>$order['id']),'goodsid');
		$item['goodstitle']=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsid']),'title');
		$item['type']=$this->fee_types[$item['type']];
	}
	//exi('num'.count($list),'error');
	exi($list);
}
?>